package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.controller.vo.music.MusicSongVO;
import com.qumitech.visualnovel.service.music.MusicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author :  ZhChNing
 * @Descriptiom :
 * @Date Created in 2019/3/4 15:58
 */
@RestController
@RequestMapping(value = "/api/music")
public class MusicController {
    @Autowired
    private MusicService musicService;


    @RequestMapping(value = "/song", method = RequestMethod.POST)
    public BaseRsp addMusicSong(@RequestBody MusicSongVO musicSongVO) {
        musicService.addMusicSong(musicSongVO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }


    @RequestMapping(value = "/song/{song_id}", method = RequestMethod.PUT)
    public BaseRsp updateMusicSong(@RequestBody MusicSongVO musicSongVO, @PathVariable(name = "song_id") String songId) {
        musicSongVO.setSongId(songId);
        musicService.updateMusicSong(musicSongVO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequestMapping(value = "/song/{song_id}", method = RequestMethod.DELETE)
    public BaseRsp removeMusicSong(@PathVariable(name = "song_id") String songId) {

        musicService.removeMusicSong(songId);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequestMapping(value = "/song/excel", method = RequestMethod.POST)
    public BaseRsp importExcel(@RequestParam("file") MultipartFile file) {
        musicService.importMusicSong(file);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequestMapping(value = "/song", method = RequestMethod.GET)
    public BaseRsp getMusicSongConfig(@RequestParam(value = "subject", required = false) Byte subject,
                                      @RequestParam(value = "song_id", required = false) String songId,
                                      @RequestParam(value = "song_name", required = false) String songName,
                                      @RequestParam(value = "voice_url", required = false) String voiceUrl,
                                      @RequestParam(value = "lyric_url", required = false) String lyricUrl,
                                      @RequestParam(value = "author", required = false) String author,
                                      @RequestParam(value = "singer", required = false) String singer,
                                      @RequestParam(value = "size", required = false) Integer size,
                                      @RequestParam(value = "tag", required = false) String tag,
                                      @RequestParam(value = "offset", defaultValue = "0") Integer offset,
                                      @RequestParam(value = "limit", defaultValue = "20") Integer limit,
                                      @RequestParam(value = "song_type", required = false) Integer songType,
                                      @RequestParam(value = "in_use", required = false) Byte inUse
    ) {
        return new BaseRsp(ResultEnum.SUCCESS,
                musicService.listMusicSongVO(offset, limit, subject, songId, songName, songType, voiceUrl, lyricUrl, author, singer, size, tag, inUse));
    }
}
